Fix which-key--show-keymap when no bidnings found
authorJustin Burkett <justin@burkett.cc>
Mon, 26 Feb 2018 03:36:10 +0000 (22:36 -0500)
committerJustin Burkett <justin@burkett.cc>
Mon, 26 Feb 2018 03:36:10 +0000 (22:36 -0500)
which-key--get-formatted-key-bindings takes a nil argument to mean look for
global bindings which is not what we want here.

which-key.el

index 765fd37bd012f338f8f9721a668ba4ec6581b9da..818ef17d2b7f9c91247db26e229d0cea2ec69acf 100644 (file)
@@ -2337,32 +2337,37 @@ is selected interactively by mode in `minor-mode-map-alist'."
                             (cdr (assq mode-sym minor-mode-map-alist)))))
 
 (defun which-key--show-keymap (keymap-name keymap &optional prior-args all)
-  (setq which-key--current-prefix nil
-        which-key--current-show-keymap-name keymap-name
-        which-key--using-show-keymap t)
-  (when prior-args (push prior-args which-key--prior-show-keymap-args))
-  (when (keymapp keymap)
-    (let ((formatted-keys (which-key--get-formatted-key-bindings
-                           (which-key--get-keymap-bindings keymap all)
-                           nil all)))
-      (cond ((= (length formatted-keys) 0)
-             (message "which-key: Keymap empty"))
-            ((listp which-key-side-window-location)
-             (setq which-key--last-try-2-loc
-                   (apply #'which-key--try-2-side-windows
-                          formatted-keys 0 which-key-side-window-location)))
-            (t (setq which-key--pages-plist
-                     (which-key--create-pages formatted-keys))
-               (which-key--show-page 0)))))
-  (let* ((key (key-description (list (read-key))))
-         (next-def (lookup-key keymap (kbd key))))
-    (cond ((and which-key-use-C-h-commands (string= "C-h" key))
-           (which-key-C-h-dispatch))
-          ((keymapp next-def)
-           (which-key--hide-popup-ignore-command)
-           (which-key--show-keymap (concat keymap-name " " key) next-def
-                                   (cons keymap-name keymap)))
-          (t (which-key--hide-popup)))))
+  (let (unformatted-keys formatted-keys)
+    (setq which-key--current-prefix nil
+          which-key--current-show-keymap-name keymap-name
+          which-key--using-show-keymap t)
+    (when prior-args (push prior-args which-key--prior-show-keymap-args))
+    (if (and (keymapp keymap)
+             (setq unformatted-keys (which-key--get-keymap-bindings keymap all))
+             ;; need this in two steps otherwise
+             ;; `which-key--get-formatted-key-bindings' will look for global
+             ;; keys if second argument is nil
+             (setq formatted-keys (which-key--get-formatted-key-bindings
+                                   unformatted-keys nil all))
+             (> (length formatted-keys) 0))
+        (progn
+          (cond ((listp which-key-side-window-location)
+                 (setq which-key--last-try-2-loc
+                       (apply #'which-key--try-2-side-windows
+                              formatted-keys 0 which-key-side-window-location)))
+                (t (setq which-key--pages-plist
+                         (which-key--create-pages formatted-keys))
+                   (which-key--show-page 0)))
+          (let* ((key (key-description (list (read-key))))
+                 (next-def (lookup-key keymap (kbd key))))
+            (cond ((and which-key-use-C-h-commands (string= "C-h" key))
+                   (which-key-C-h-dispatch))
+                  ((keymapp next-def)
+                   (which-key--hide-popup-ignore-command)
+                   (which-key--show-keymap (concat keymap-name " " key) next-def
+                                           (cons keymap-name keymap)))
+                  (t (which-key--hide-popup)))))
+      (message "which-key: No bindings found in %s" keymap-name))))
 
 (defun which-key--evil-operator-filter (binding)
   (let ((def (intern (cdr binding))))